from peewee import *

from easymoney.framework.logging_config import configure_logging

# 先配置日志
configure_logging()

# Connect to a MySQL database on network.
db = MySQLDatabase('easy_money_db', user='root', password='admin',
                   host='127.0.0.1', port=3306)


# Defining entities

class StockEntity(Model):
    """

    这是一个映射easy_money_db.stock表实体类
    Model 是 peewe 的一个基类，可以帮助你做和数据库的交互
    """
    stock_code = CharField(unique=True)
    stock_name = CharField(null=True)
    stock_industry = CharField(null=True)

    class Meta:
        database = db
        table_name = 'stock'


class MainForceControlEntity(Model):
    """
    主力控盘
    """
    stock_code = CharField(unique=True)
    date = DateField(null=True)
    value = DecimalField(null=True)

    class Meta:
        database = db
        table_name = 'main_force_control'


class StockDistributionEntity(Model):
    """
    筹码分布
    """
    stock_code = CharField(unique=True)
    date = DateField(null=True)
    profit_ratio = DecimalField(null=True)
    average_cost = DecimalField(null=True)
    ninety_cost_low = DecimalField(null=True)
    ninety_cost_high = DecimalField(null=True)
    ninety_concentration = DecimalField(null=True)

    class Meta:
        database = db
        table_name = 'stock_distribution'


class InvestmentRecommendationEntity(Model):
    """
    最新买入评级的个股
    """
    stock_code = CharField(unique=True)
    stock_name = CharField(null=True)
    frequency = IntegerField(null=True)
    stock_price = DecimalField(
        max_digits=10,  # 总位数（包含小数位）
        decimal_places=2,  # 小数位数
        null=True,  # 允许NULL值
        verbose_name='股票当前价格'  # Peewee的字段注释（非数据库原生注释）
    )
    pe_ttm = DecimalField(
        max_digits=10,  # 总位数（包含小数位）
        decimal_places=2,  # 小数位数
        null=True,  # 允许NULL值
        verbose_name='动态市盈率TTM'
    )

    class Meta:
        database = db
        table_name = 'investment_recommendation'
